import { request } from '../../utils/request'
let that
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperList:[],
    scrollList:[],
    topList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    that = this

    const swiperListData = await request('banner',{type:2})
    that.setData({
      swiperList:swiperListData.banners
    })

    const scrollListData = await request('personalized')
    that.setData({
      scrollList:scrollListData.result
    })

    const topListArr = [19723756, 3779629, 2884035, 3778678]
    let index=0
    let topListDataArr = []
    while(index<topListArr.length){
      let id = topListArr[index]
      const topListData_name = await request('playlist/detail',{
        id
      })
      const topListData_track = await request('playlist/track/all',{
        id,
        limit:5
      })
      topListDataArr.push({
        listId:id,
        name:topListData_name.playlist.name,
        songs:topListData_track.songs
      })
      that.setData({
        topList:topListDataArr
        })
      index++
    }
  },
  navigateToRecommend: () => {
    wx.navigateTo({
      url:'/pages/recommend/recommend'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})